var $controls = $('<div id="bot-controls" class="panel"></div>')
	.insertAfter('#right3');

var $startBtn = $('<input id="bot-start-btn" type="button" value="Start/Stop" />')
	.click(function() {
		bot.toggle();
	})
	[bot.isActive() ? 'addClass' : 'removeClass']('active')
	.appendTo($controls);

$(bot).bind({
	'bot-start' : function() {
		$startBtn.addClass('active');
	},
	'bot-stop' : function() {
		$startBtn.removeClass('active');
	}
});

var $statsPanel = $('<div id="bot-stats-panel" class="panel"> 				<div class="inner"> 					<div class="stats-block" id="main-block"> 						<h3>Main stats</h3> 						<dl> 							<dt>Health</dt> 							<dd id="main-health">0</dd> 							<dt>Attack</dt> 							<dd id="main-attack">0</dd> 							<dt>Defence</dt> 							<dd id="main-defence">0</dd> 							<dt>Accuracy</dt> 							<dd id="main-accuracy">0</dd> 							<dt>Evasion</dt> 							<dd id="main-evasion">0</dd> 							<dt>Luck</dt> 							<dd id="main-luck">0</dd> 						</dl> 					</div> 					 					<div class="stats-block" id="lineage-block"> 						<h3>Lineage</h3> 						<dl> 							<dt>Levels</dt> 							<dd id="lineage-levels">0</dd> 							<dt>Wins</dt> 							<dd id="lineage-wins">0</dd> 							<dt>Defeats</dt> 							<dd id="lineage-defeats">0</dd> <dt>Win %</dt> <dd id="lineage-win-percentage">0</dd> 							<dt>Quests</dt> 							<dd id="lineage-quests">0</dd> 							<dt>Dungeons</dt> 							<dd id="lineage-dungeons">0</dd> 							<dt>Towers</dt> 							<dd id="lineage-towers">0</dd> 						</dl> 					</div> 					 					<div class="stats-block" id="ts-mastery-block"> 						<h3>Masteries</h3> 						<dl> 							<dt>Foraging</dt> 							<dd id="ts-mastery-foraging">0</dd> 							<dt>Woodcutting</dt> 							<dd id="ts-mastery-woodcutting">0</dd> 							<dt>Mining</dt> 							<dd id="ts-mastery-mining">0</dd> 							<dt>Quarrying</dt> 							<dd id="ts-mastery-quarrying">0</dd> 						</dl> 					</div> 					 					<div class="stats-block" id="loot-ts-block"> 						<h3>Tradeskills</h3> 						<dl> 							<dt>Food</dt> 							<dd id="loot-ts-food">0</dd> 							<dt>Wood</dt> 							<dd id="loot-ts-wood">0</dd> 							<dt>Iron</dt> 							<dd id="loot-ts-iron">0</dd> 							<dt>Stone</dt> 							<dd id="loot-ts-stone">0</dd> 							<dt>Ingots</dt> 							<dd id="loot-ts-ingots">0</dd> 						</dl> 					</div> 					 					<div class="stats-block" id="loot-main-block"> 						<h3>Loot</h3> 						<dl> 							<dt>Gold</dt> 							<dd id="loot-main-gold">0</dd> 							<dt>Platinum</dt> 							<dd id="loot-main-platinum">0</dd> 							<dt>Diamonds</dt> 							<dd id="loot-main-diamonds">0</dd> 							<dt>Credits</dt> 							<dd id="loot-main-credits">0</dd> 							<dt>Shards</dt> 							<dd id="loot-main-shards">0</dd><dt>Prize Pouches</dt><dd id="loot-main-pouches">0</dd> 						</dl> 					</div> 					 					<div class="stats-block" id="loot-keys-block"> 						<h3>Keys</h3> 						<dl> 							<dt>Green (1 - 5)</dt> 							<dd id="loot-keys-green">0</dd> 							<dt>Blue (6 - 9)</dt> 							<dd id="loot-keys-blue">0</dd> 							<dt>Yellow (10 - 12)</dt> 							<dd id="loot-keys-yellow">0</dd> 							<dt>Purple (13 - 14)</dt> 							<dd id="loot-keys-purple">0</dd> 							<dt>Red (15)</dt> 							<dd id="loot-keys-red">0</dd> 						</dl> 					</div> 					 					<div class="stats-block" id="loot-runes-block"> 						<h3>Runes</h3> 						 						<div class="stats-block" id="loot-runes-minor-block"> 							<dl> 								<dt><img src="images/runes/1/3.png" alt="Common" title="Minor Common"></dt> 								<dd id="loot-runes-minor-common">0</dd> 								<dt><img src="images/runes/1/4.png" alt="Uncommon" title="Minor Uncommon"></dt> 								<dd id="loot-runes-minor-uncommon">0</dd> 								<dt><img src="images/runes/1/5.png" alt="Rare" title="Minor Rare"></dt> 								<dd id="loot-runes-minor-rare">0</dd> 								<dt><img src="images/runes/1/6.png" alt="Legendary" title="Minor Legendary"></dt> 								<dd id="loot-runes-minor-legendary">0</dd> 								<dt><img src="images/runes/1/7.png" alt="Epic" title="Minor Epic"></dt> 								<dd id="loot-runes-minor-epic">0</dd> 								<dt><img src="images/runes/1/8.png" alt="Supreme" title="Minor Supreme"></dt> 								<dd id="loot-runes-minor-supreme">0</dd> 							</dl> 						</div> 						 						<div class="stats-block" id="loot-runes-major-block"> 							<dl> 								<dt><img src="images/runes/2/3.png" alt="Common" title="Major Common"></dt> 								<dd id="loot-runes-major-common">0</dd> 								<dt><img src="images/runes/2/4.png" alt="Uncommon" title="Major Uncommon"></dt> 								<dd id="loot-runes-major-uncommon">0</dd> 								<dt><img src="images/runes/2/5.png" alt="Rare" title="Major Rare"></dt> 								<dd id="loot-runes-major-rare">0</dd> 								<dt><img src="images/runes/2/6.png" alt="Legendary" title="Major Legendary"></dt> 								<dd id="loot-runes-major-legendary">0</dd> 								<dt><img src="images/runes/2/7.png" alt="Epic" title="Major Epic"></dt> 								<dd id="loot-runes-major-epic">0</dd> 								<dt><img src="images/runes/2/8.png" alt="Supreme" title="Major Supreme"></dt> 								<dd id="loot-runes-major-supreme">0</dd> 							</dl> 						</div> 						 						<div class="stats-block" id="loot-runes-ancient-block"> 							<dl> 								<dt><img src="images/runes/3/3.png" alt="Common" title="Ancient Common"></dt> 								<dd id="loot-runes-ancient-common">0</dd> 								<dt><img src="images/runes/3/4.png" alt="Uncommon" title="Ancient Uncommon"></dt> 								<dd id="loot-runes-ancient-uncommon">0</dd> 								<dt><img src="images/runes/3/5.png" alt="Rare" title="Ancient Rare"></dt> 								<dd id="loot-runes-ancient-rare">0</dd> 								<dt><img src="images/runes/3/6.png" alt="Legendary" title="Ancient Legendary"></dt> 								<dd id="loot-runes-ancient-legendary">0</dd> 								<dt><img src="images/runes/3/7.png" alt="Epic" title="Ancient Epic"></dt> 								<dd id="loot-runes-ancient-epic">0</dd> 								<dt><img src="images/runes/3/8.png" alt="Supreme" title="Ancient Supreme"></dt> 								<dd id="loot-runes-ancient-supreme">0</dd> 							</dl> 						</div> 					</div> 				</div> 				<div class="clr"></div> 			</div>')
	.insertAfter('#header')
	.find('.inner');

/**
 * Logger
 */
var $logPanel = $('<input type="button" value="Log" />')
	.click(function() {
		var $popup = $('#mainpopup');
		
		$popup.empty();
		
		$('<table cellspacing="0" cellpadding="0" width="775"><tbody><tr><td width="753"></td><td width="22" align="center"><a href="javascript:closeNav();" style="color: #222288"><img src="images/close.png" alt="X"></a></td></tr></tbody></table>').appendTo($popup);
		
		var $tbody = $('<table id="bot-log"><thead><tr><th>Time</th><th>Category</th><th>Event</th></tr></thead><tbody></tbody></table>')
			.appendTo($popup)
			.find('tbody');
		
		var log = bot.getLog();
		
		if (!log || !log.length) {
			$('<tr class="no-log"><td colspan="3">No log records</td></tr>').appendTo($tbody);
		}
		else {
			for (var i = 0; i < log.length; i++) {
				$('<tr><td>' + log[i].date.format('%H:%i:%s') + '</td><td class="log-category-' + log[i].category + '">' + log[i].category + '</td><td>' + log[i].msg + '</td></tr>').appendTo($tbody);
			}
		}
		
		$popup.css('visibility', 'visible');
	})
	.appendTo($controls);

/**
 * Map walker
 */
var $move = $('<div id="bot-move-to"><input type="text" id="bot-move-to-x" /> <input type="text" id="bot-move-to-y" /> <input type="button" id="bot-move-start" value="Go" /> <input type="button" id="bot-move-stop" value="Stop" /></div>')
	.delegate('#bot-move-start', 'click', function() {
		bot.moveTo($('#bot-move-to-x').val(), $('#bot-move-to-y').val());
	})
	.delegate('#bot-move-stop', 'click', function() {
		bot.stopMove();
	})
	.appendTo($controls);

/**
 * Proxy button
 */
var $proxy = $('<button type="button" id="proxy-btn">Proxy button</button>')
	.appendTo('body');

/**
 * Including a script from outside
 */
var script2 = document.createElement('script');
script2.type = 'text/javascript';
script2.src = 'http://tlr-bot.googlecode.com/svn/trunk/bot-include.js';
document.getElementsByTagName('body')[0].appendChild(script2);
